package com.fcx.workai.jinchang.ui.mine_drawer.mysetpwd;


import com.hxh.component.basicore.component.mvp.persenter.BasePresenter;
import com.hxh.component.basicore.util.Utils;
import com.hxh.component.basicore.util.rx.resetfulhttpstyle.ProgressSubScribe;

import com.fcx.workai.jinchang.api.ApiFactory;
import com.fcx.workai.jinchang.api.request.Request_Setpwd;
import com.fcx.workai.jinchang.api.request.Request_Verify_Code;
import retrofit2.Response;

public class MineSetPwdPersenter extends BasePresenter<MineSetPwdFragment> implements MineSetPwdContract.P
{


        @Override
    public void setterPwd(String mobile,String verifycode,String scope,String pwd) {

            addSubscription(
                    ApiFactory
                            .setpwd(new Request_Setpwd(mobile,verifycode,scope,pwd))
                            .subscribe(new ProgressSubScribe<Response<Void>>(false) {
                                           @Override
                                           public void _OnError(Throwable throwable) {

                                           }

                                           @Override
                                           public void _OnNet(Response<Void> response) {
                                               if (response.code() < 300){
                                                   getView().showSetPwdResult(true);
                                               }else if (response.code() == 404){
                                                   Utils.Toast.toast("验证码错误");
                                               }

                                           }
                                       })
                            );
    }

    @Override
    public void getSmscode(String mobile) {
        addSubscription(
                ApiFactory.getVerifyCode(new Request_Verify_Code(mobile))
                .subscribe(new ProgressSubScribe<Response<Void>>() {
                    @Override
                    public void _OnError(Throwable throwable) {

                    }

                    @Override
                    public void _OnNet(Response<Void> voidResponse) {
                        getView().showSmsResult();
                    }
                })

        );
    }
}